﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HSDc.RingleFlow.Kernel.DBPersit.Dao.Util;

namespace HSDc.RingleFlow.Kernel.DBPersit.DbOrg.Dao
{
    internal class EmpDao
    {
        internal EmployeeDto GetEmployee(string userId)
        {
            RingleFlowEntities entity = ConnectionFactory.GetInstance().GetEntities();
            var emp = (from e in entity.EmployeeDto
                       where (e.Emp_UserID.ToLower() == userId.ToLower())
                       select e).Single();
            return emp;
        }

        internal DepartmentDto RetrieveEmpMainDept(string userId)
        {
            RingleFlowEntities entity = ConnectionFactory.GetInstance().GetEntities();
            var dept = (from d in entity.DepartmentDto
                        join de in entity.EmpDeptDto on d.Dept_ID equals de.Belong_Dept_ID
                        join e in entity.EmployeeDto on de.Emp_ID equals e.Emp_ID
                        where (e.Emp_UserID.ToLower() == userId.ToLower() &&
                                   de.Primary_Dept)
                        select d).Single();
            return dept;
        }

        internal List<DepartmentDto> RetrieveEmpPartimeDept(string userId)
        {
            RingleFlowEntities entity = ConnectionFactory.GetInstance().GetEntities();
            var dept = from d in entity.DepartmentDto
                        join de in entity.EmpDeptDto on d.Dept_ID equals de.Belong_Dept_ID
                        join e in entity.EmployeeDto on de.Emp_ID equals e.Emp_ID
                        where (e.Emp_UserID.ToLower() == userId.ToLower() &&
                                   (!de.Primary_Dept))
                        select d;
            return dept.ToList();
        }
    }
}
